package com.itzh.proxy.custom;

import com.itzh.proxy.state.Person;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class CustomMaiPo implements GPInvocationHandler{

    private Person target;

    public Object getInstance(Person target) throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        this.target = target;
        Class<? extends Person> clazz = target.getClass();

        return GPProxy.newProxyInstance(new GPClassLoader(),clazz.getInterfaces(),this);
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Exception{
        System.out.println("开始");
        method.invoke(this.target,args);
        System.out.println("结束");
        return null;
    }
}
